﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using LantingConnect.Controller;
using Lanting.Model;
using Lanting.Utilities.NetConn;
using DevExpress.XtraTab;

namespace LantingConnect.View
{
    public partial class Form_Index : DevExpress.XtraEditors.XtraForm
    {
        #region 全局变量、常量
        public Controller_Index controller_index;
        private string type = "icitem";

        #endregion

        #region 控件初始化

        public Form_Index()
        {
            InitializeComponent();
        }
        #endregion

        #region 窗体事件

        #region 事件-窗体加载

        private void Form_Index_Load(object sender, EventArgs e)
        {
            List<ColumnData> list = new List<ColumnData>();
            list.AddRange(new ColumnData[] {
                new ColumnData("FName", "FName", "产品名称"),
                new ColumnData("FNumber", "FNumber", "产品代码"),

                new ColumnData("FABCCls","FABCCls","ABC类别"),
                new ColumnData("FAcctID","FAcctID","存货科目"),
                new ColumnData("FInspectionLevel","FInspectionLevel","检验方式"),
                new ColumnData("FInspectionProject", "FInspectionProject", "检验方案"),
                new ColumnData("FIsCharSourceItem","FIsCharSourceItem","产品对应特性"),
                new ColumnData("FItemID", "FItemID", "产品内码"),
                new ColumnData("FKFPeriod","FKFPeriod","保质期天"),
                new ColumnData("FLastCheckDate", "FLastCheckDate", "上次盘点日期"),
                new ColumnData("FLength","FLength","长度"),
                new ColumnData("FLowestBomCode", "FLowestBomCode", "低层码"),
                new ColumnData("FModel","FModel","规格型号"),
                new ColumnData("FNetWeight","FNetWeight","净重"),
                new ColumnData("FProChkMde","FProChkMde","产品检验方式"),
                new ColumnData("FProductPrincipal", "FProductPrincipal", "生产负责人"),
                new ColumnData("FSalePrice","FSalePrice","销售单价"),
                new ColumnData("FShortNumber", "FShortNumber", "产品简码"),
                new ColumnData("FSource","FSource","来源"),
            });
            //创建数据列并加载布局文件
            uC_Grid1.Function_CreateCloumns(list, false, true, "ProConcreteList");
            //表头及行内容居中显示
            uC_Grid1.getGridView.Appearance.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
            uC_Grid1.getGridView.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
            Function_getIcitemList();
            list = new List<ColumnData>();
            list.AddRange(new ColumnData[] {
                new ColumnData("FBillNo","FBillNo","编号"),
                new ColumnData("FExchangeRate", "FExchangeRate", "汇率"),
                new ColumnData("FFetchAdd","FFetchAdd","交货地点"),
                new ColumnData("FFetchDate", "FFetchDate", "交货日期"),
                new ColumnData("FFetchStyle","FFetchStyle","交货方式"),
                new ColumnData("FMultiCheckLevel1", "FMultiCheckLevel1", "一审"),
                new ColumnData("FMultiCheckDate1","FMultiCheckDate1","一级审核日期"),
                new ColumnData("FMultiCheckLevel2", "FMultiCheckLevel2", "二审"),
                new ColumnData("FMultiCheckDate2","FMultiCheckDate2","二级审核日期"),
                new ColumnData("FMultiCheckLevel3", "FMultiCheckLevel3", "三审"),
                new ColumnData("FMultiCheckDate3","FMultiCheckDate3","三级审核日期"),
                new ColumnData("FMultiCheckLevel4", "FMultiCheckLevel4", "四审"),
                new ColumnData("FMultiCheckDate4","FMultiCheckDate4","四级审核日期"),
                new ColumnData("FMultiCheckLevel5", "FMultiCheckLevel5", "五审"),
                new ColumnData("FMultiCheckDate5","FMultiCheckDate5","五级审核日期"),
                new ColumnData("FMultiCheckLevel6", "FMultiCheckLevel6", "六审"),
                new ColumnData("FMultiCheckDate6","FMultiCheckDate6","六级审核日期"),
                new ColumnData("FNote", "FNote", "备注"),
                new ColumnData("FPayDate","FPayDate","付款日期"),
                new ColumnData("FPayStyle", "FPayStyle", "付款方式"),
                new ColumnData("FPOOrdBillNo","FPOOrdBillNo","采购订单号"),
                new ColumnData("FSettleDate", "FSettleDate", "结算日期"),
                new ColumnData("FSettleID","FSettleID","结算方式"),
                new ColumnData("FStatus","FStatus","状态"),

            });
            //创建数据列并加载布局文件
            uC_Grid2.Function_CreateCloumns(list, false, true, "SEOrderList");
            //表头及行内容居中显示
            uC_Grid2.getGridView.Appearance.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
            uC_Grid2.getGridView.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
            Function_getAllSEOrderList();
        }
        #endregion

        #region 事件-选项卡点击事件

        private void tabPage_1_Click(object sender, EventArgs e)
        {
            XtraTabControl obj = sender as XtraTabControl;
            DevExpress.XtraTab.XtraTabPage page = obj.SelectedTabPage;
            if (page.Name == "xtraTabPage1")
            {
                type = "icitem";
            }
            else if (page.Name == "xtraTabPage2")
            {
                type = "allIn";
            }
        }
        #endregion

        #region 事件-导出按钮点击
        private void bt_export_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string filename = "物料表";

            if (type == "icitem")
            {

                uC_Grid1.Function_ExportToXls(filename);
            }
            else
            {
                filename = "销售订单表";

                uC_Grid2.Function_ExportToXls(filename);
            }
        }
        #endregion

        #region 事件-检索按钮点击
        private void bt_search_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (type == "icitem")
            {
                Function_getIcitemList();
            }
            else
            {
                Function_getAllSEOrderList();
            }
        }
        #endregion

        #endregion


        #region 外部方法-获取数据列表
        public void Function_getIcitemList()
        {
            //数据加载中
            uC_Grid1.getGridView.ShowLoadingPanel();
            //初始化分页控件
            uC_Grid1.Function_InitPageNavigation();
            //获取实际测量数据列表
            controller_index.Function_getAllIcitemList(1, uC_Grid1.pageSize, 0, text_key.Text);
        }
        #endregion

        #region 外部方法-获取数据列表
        public void Function_getAllSEOrderList()
        {
            //数据加载中
            uC_Grid2.getGridView.ShowLoadingPanel();
            //初始化分页控件
            uC_Grid2.Function_InitPageNavigation();
            //获取实际测量数据列表
            controller_index.Function_getAllSEOrderList(1, uC_Grid2.pageSize, 0, text_key.Text);
        }
        #endregion

        #region 响应-获取数据列表
        public void Handler_dbGetIcitemListIMP(Result result)
        {
            uC_Grid1.Function_BindDataSource(result.list, result.total, "IcitemList");
            text_key.Text = "";
        }

        #endregion

        #region 响应-获取数据列表
        public void Handler_dbGetSEOrderListIMP(Result result)
        {
            uC_Grid2.Function_BindDataSource(result.list, result.total, "SEOrderList");
            text_key.Text = "";
        }

        #endregion

       

    }
}